package com.socket.nio.nio.bytebuf;

import com.socket.nio.nio.util.ByteBufPrinter;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.CompositeByteBuf;

import java.nio.charset.Charset;

/**
 * @author Hexudong
 * @date 2025/4/19
 */
public class TestCompositeByteBuf {
  public static void main(String[] args) {
    ByteBuf buf1 = ByteBufAllocator.DEFAULT.buffer();
    buf1.writeBytes(Charset.defaultCharset().encode("abcde").array());

    ByteBuf buf2 = ByteBufAllocator.DEFAULT.buffer();
    buf1.writeBytes(Charset.defaultCharset().encode("fghij").array());

    CompositeByteBuf buffer1 = ByteBufAllocator.DEFAULT.compositeBuffer();
    buffer1.addComponents(true, buf1, buf2);
    ByteBufPrinter.prettyPrint(buffer1);

    CompositeByteBuf buffer2 = ByteBufAllocator.DEFAULT.compositeBuffer();
    buffer2.addComponent(true, buf1);
    buffer2.addComponent(true, buf2);
    ByteBufPrinter.prettyPrint(buffer2);
  }
}
